import pymysql.cursors
connection = pymysql.connect(host='localhost',
                             user='root',
                             password='haosql',
                             db='demo',
                             charset='utf8mb4',
                             cursorclass=pymysql.cursors.DictCursor)

try:
    with connection.cursor() as cursor:
        # Create a new record
        creat_table_sql='''
        CREATE TABLE `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `email` varchar(255) COLLATE utf8_bin NOT NULL,
    `password` varchar(255) COLLATE utf8_bin NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
AUTO_INCREMENT=1 ;
        '''
    #     sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
    #     for i in range(1,1000):
    #         cursor.execute(sql, ('webmaster@python.org', i))
    #
    # # connection is not autocommit by default. So you must commit to save
    # # your changes.
    # connection.commit()

    with connection.cursor() as cursor:
        print(cursor.execute("show databases"))
        
        # Read a single record
        # sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
        # cursor.execute(sql, ('webmaster@python.org',))
        # result = cursor.fetchall()
        # for i in result:
        #     print(i['password'])
finally:
    connection.close()